package com.kehutong.applet.admin;

import com.kehutong.applet.entity.AppletMenuEntity;
import com.kehutong.applet.entity.AppletMenuPageEntity;
import com.kehutong.applet.service.AppletMenuService;
import com.kehutong.common.util.Token;
import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;
import org.coraframework.orm.Pool;

/**
 * @program: kht
 * @description: 控制
 * @author: joneron
 * @create: 2021/5/24
 **/
@MvcAction
@ReqMapping("/admin/crm/applet/menu/two")
public class AppletMenuTwoController {

    @Inject
    AppletMenuService appletMenuService;

    @ReqMapping("/list")
    @HasPermission("crm:applet:menu:two:view")
    public Object list(JSONObject jsonObject) {
        return appletMenuService.findMenuList(jsonObject);
    }

    @ReqMapping("/page")
    @HasPermission("crm:applet:menu:two:view")
    public Object page(JSONObject jsonObject) {
        return appletMenuService.findMenuPage(jsonObject);
    }

    @Bean(newInstance=true, copy=true)
    @HasPermission("crm:applet:menu:two:edit")
    @ReqMapping("/save")
    public Object save(AppletMenuPageEntity appletMenuPageEntity, Token token) {
        appletMenuPageEntity.setCreateName(token.getUsername());
        return appletMenuService.save(appletMenuPageEntity);
    }

    @Bean(copy=true)
    @HasPermission("crm:applet:menu:two:edit")
    @ReqMapping("/update")
    public Object update(AppletMenuPageEntity appletMenuEntity) {

        return appletMenuService.update(appletMenuEntity);
    }

    @HasPermission("crm:applet:menu:two:edit")
    @ReqMapping("/delete")
    public Object delete(AppletMenuPageEntity appletMenuEntity) {

        return appletMenuService.deleteMenuById(appletMenuEntity.getId());
    }

    @ReqMapping("/get")
    public Object get(AppletMenuPageEntity entity) {
        return Result.success(entity);
    }
}
